package megrez.job.custom.tasks;

import java.time.Duration;
import java.util.SplittableRandom;

import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;
import megrez.job.common.JobException;
import megrez.job.common.Nap;

/**
 * 任务异常
 * 
 * @author Lucky Yang
 * @since 2.6.9
 */
@Slf4j
@Component
public class ExceptionTask {
    private static final SplittableRandom RANDOM = new SplittableRandom();

    public void execute() {
        Nap.after(Duration.ofMillis(RANDOM.nextLong(3000L)))
                .doThis(() -> log.info("{}.execute", ExceptionTask.class.getName()));

        if (RANDOM.nextBoolean()) {
            throw new JobException("任务异常");
        }
    }

}
